package com.soilflow.web.controller.dahu;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.soilflow.common.domain.DahuBusiness;
import com.soilflow.system.service.IDahuBusinessService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.soilflow.common.annotation.Log;
import com.soilflow.common.core.controller.BaseController;
import com.soilflow.common.core.domain.AjaxResult;
import com.soilflow.common.enums.BusinessType;
import com.soilflow.common.utils.poi.ExcelUtil;
import com.soilflow.common.core.page.TableDataInfo;

/**
 * 商家Controller
 * 
 * @author party
 * @date 2023-10-26
 */
@RestController
@RequestMapping("/system/business")
public class DahuBusinessController extends BaseController {
    @Autowired
    private IDahuBusinessService dahuBusinessService;

    /**
     * 查询商家列表
     */
    @PreAuthorize("@ss.hasPermi('system:business:list')")
    @GetMapping("/list")
    public TableDataInfo list(DahuBusiness dahuBusiness)
    {
        startPage();
        List<DahuBusiness> list = dahuBusinessService.selectDahuBusinessList(dahuBusiness);
        return getDataTable(list);
    }

    /**
     * 对违规发布商品信息的用户进行处罚 这里是将商家状态变为1 暂停营业
     */
    @PostMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody Map params) {
        Map map = dahuBusinessService.updateStatus(params);
        return AjaxResult.success(map);
    }

    /**
     * 商家解冻
     */
    @PostMapping("/thaw")
    public AjaxResult thaw(@RequestBody Map params) {
        Map map = dahuBusinessService.thaw(params);
        return AjaxResult.success(map);
    }


    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:business:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DahuBusiness dahuBusiness)
    {
        List<DahuBusiness> list = dahuBusinessService.selectDahuBusinessList(dahuBusiness);
        ExcelUtil<DahuBusiness> util = new ExcelUtil<DahuBusiness>(DahuBusiness.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取商家详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:business:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dahuBusinessService.selectDahuBusinessById(id));
    }

    /**
     * 新增商家
     */
    @PreAuthorize("@ss.hasPermi('system:business:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DahuBusiness dahuBusiness)
    {
        return toAjax(dahuBusinessService.insertDahuBusiness(dahuBusiness));
    }

    /**
     * 修改商家
     */
    @PreAuthorize("@ss.hasPermi('system:business:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DahuBusiness dahuBusiness)
    {
        return toAjax(dahuBusinessService.updateDahuBusiness(dahuBusiness));
    }
    /**
     * 商家申请审核
     */
    @PutMapping("/toexamineupdate")
    public AjaxResult toexamineupdate(@RequestBody DahuBusiness dahuBusiness)
    {
        return toAjax(dahuBusinessService.toexamineupdate(dahuBusiness));
    }
    /**
     * 删除商家
     */
    @PreAuthorize("@ss.hasPermi('system:business:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dahuBusinessService.deleteDahuBusinessByIds(ids));
    }
}
